/**
 * @author Jason Pratt
 */

package edu.cmu.cs.stage3.alice.authoringtool;

import edu.cmu.cs.stage3.alice.authoringtool.py.AliceStyle; // bgColor, fgColor

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.SystemColor;

import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.Border;

import edu.cmu.cs.stage3.alice.authoringtool.editors.variablegroupeditor.VariableGroupEditor;

public class PropertyPanel extends javax.swing.JPanel {

 protected edu.cmu.cs.stage3.alice.core.Element element;
 protected VariableGroupEditor variableGroupEditor = new VariableGroupEditor();

 public PropertyPanel() {
  jbInit();
  propertyGroupCombo.addItemListener(
    new java.awt.event.ItemListener() {
     public void itemStateChanged( java.awt.event.ItemEvent ev ) {
      java.awt.CardLayout cardLayout = (java.awt.CardLayout)PropertyPanel.this.propertyManipulationPanel.getLayout();
      cardLayout.show( PropertyPanel.this.propertyManipulationPanel, (String)ev.getItem() );
     }
    }
  );
 }

 public edu.cmu.cs.stage3.alice.core.Element getElement() {
  return element;
 }

 public void setElement( edu.cmu.cs.stage3.alice.core.Element element ) {
  this.element = element;

  refreshGUI();
 }

 public void refreshGUI() {
  propertyManipulationPanel.removeAll();
  propertyGroupCombo.removeAllItems();
  if( element != null ) {
   if( element instanceof edu.cmu.cs.stage3.alice.core.Sandbox ) {
    variableGroupEditor.setVariableObjectArrayProperty( ((edu.cmu.cs.stage3.alice.core.Sandbox)element).variables );
    propertyManipulationPanel.add( variableGroupEditor, element.name.get() + "'s variables" );
    propertyGroupCombo.addItem( element.name.get() + "'s variables" );
   }
  }
  revalidate();
  repaint();
 }

 ////////////////////
 // Autogenerated
 ////////////////////

 BorderLayout borderLayout1 = new BorderLayout();
 JPanel propertySubPanel = new JPanel();
 BorderLayout borderLayout2 = new BorderLayout();
 JComboBox propertyGroupCombo = new JComboBox();
 Border border1;
 JScrollPane propertyScrollPane = new JScrollPane();
 Border border2;
 Border border5;
 JPanel propertyManipulationPanel = new JPanel();
 Border border6;

 CardLayout cardLayout1 = new CardLayout();

 private void jbInit () {
  border1 = BorderFactory.createEmptyBorder(8,8,8,8);
  border2 = BorderFactory.createLineBorder(SystemColor.controlText,1);
  border5 = BorderFactory.createEmptyBorder(2,2,2,2);
  border6 = BorderFactory.createLineBorder(SystemColor.controlText,1);
  this.setLayout(borderLayout1);
  propertySubPanel.setLayout(borderLayout2);
  propertySubPanel.setBorder(border1);

  this.setBackground(AliceStyle.bgColorPP); //
  this.setForeground(AliceStyle.fgColorPP); //

  this.setMinimumSize(new Dimension(0, 0));
  propertyManipulationPanel.setLayout(cardLayout1);
  borderLayout2.setHgap(8);
  borderLayout2.setVgap(8);
  propertyManipulationPanel.setBackground(Color.white);
  this.add(propertySubPanel, BorderLayout.CENTER);
  propertySubPanel.add(propertyGroupCombo, BorderLayout.NORTH);
  propertySubPanel.add(propertyScrollPane, BorderLayout.CENTER);
  propertyScrollPane.getViewport().add(propertyManipulationPanel, null);
 }

}
